SET SERVEROUTPUT ON SIZE 1000000;
SET VERIFY OFF

DECLARE
	l_total_extracted	NUMBER;
	l_total_imported	NUMBER;
	l_total_extracted_2	NUMBER;
	l_total_imported_2	NUMBER;				
	l_func_id			VARCHAR2(100):='CAPARREC_MEMO_LINE';
	l_code VARCHAR2(100):=UPPER('&1');

BEGIN
	SELECT COUNT(1)
	INTO l_total_extracted        
	from   AR_MEMO_LINES_ALL_B amlal,
	       hr_organization_information hoi,
	       GL_SETS_OF_BOOKS A
    where  hoi.org_information_context = 'Operating Unit Information'
    and    hoi.org_information3 = TO_CHAR(A.SET_OF_BOOKS_ID)
    and    hoi.organization_id = amlal.org_id
    AND    UPPER(A.SHORT_NAME) = l_code;
	
	SELECT COUNT(1) 
	INTO l_total_imported
	FROM CRST_AR_MEMO_LINES_ALL_B;

	SELECT COUNT(1)
	INTO l_total_extracted_2        
	from AR_MEMO_LINES_ALL_TL A,
		 AR_MEMO_LINES_ALL_B amlal,
	     hr_organization_information hoi,
	     GL_SETS_OF_BOOKS B
    where A.org_id IN amlal.org_id  
    and A.memo_line_id IN amlal.memo_line_id
    and	hoi.org_information_context = 'Operating Unit Information'
	and    hoi.org_information3 = TO_CHAR(B.SET_OF_BOOKS_ID)
	and    hoi.organization_id = amlal.org_id
    AND UPPER(B.SHORT_NAME) = l_code;
    
	SELECT COUNT(1) 
	INTO l_total_imported_2
	FROM CRST_AR_MEMO_LINES_ALL_TL;

	dbms_output.put_line('Function: '||l_func_id);		
	dbms_output.put_line('Total Extracted: '||TO_CHAR(l_total_extracted)) ;
	dbms_output.put_line('Total Imported:  '||TO_CHAR(l_total_imported));
	dbms_output.put_line('Total Extracted_2: '||TO_CHAR(l_total_extracted_2)) ;
	dbms_output.put_line('Total Imported_2:  '||TO_CHAR(l_total_imported_2));
	IF l_total_extracted <> l_total_imported THEN
		dbms_output.put_line('Error: No. of Records do not match!');
	END IF;	
	IF l_total_extracted_2 <> l_total_imported_2 THEN
		dbms_output.put_line('Error: No. of Records do not match!');
	END IF;	
						
EXCEPTION
	WHEN OTHERS THEN	
		dbms_output.put_line('Function Error: '||l_func_id);			
END;
/
